package com.dckxx.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dckxx.common.vo.Result;
import com.dckxx.entity.StudentEntity;
import com.dckxx.service.impl.IStudentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("student")
public class StudentController {

    @Resource
    private IStudentService studentService;

    @GetMapping(value = "/page")
    public Result<?> queryPageList(StudentEntity studentEntity,
                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        QueryWrapper<StudentEntity> queryWrapper = Wrappers.query(studentEntity);
        Page<StudentEntity> page = new Page<>(pageNo, pageSize);
        IPage<StudentEntity> pageList = studentService.page(page, queryWrapper);
        return Result.ok(pageList);
    }
    @GetMapping("list")
    public Result<?> getList(){
        List<StudentEntity> list = studentService.list();
        return Result.ok(list);
    }

    @GetMapping("name/{name}")
    public Result<?> getList(@PathVariable("name")String name){
        StudentEntity student = studentService.getStudentByName(name);
        return Result.ok(student);
    }

    @GetMapping("ac")
    public Result<?> ac(){
        StudentEntity student = new StudentEntity();
        List<StudentEntity> studentEntities = student.selectAll();
        return Result.ok(studentEntities);
    }
}
